export const axiosJsTemplate = () => {
  return `
    import axios from 'axios'
    /**
     * @property {Response:{code: number, message:string, data:any}}
     */
    
    const instance = axios.create({
        headers: {
          'token': ''
        },
        // 请求超时时间
        timeout: 5000,
      })
      /**
       *  @type {Function}
       *  @param {Object} config
       *  @return {Promise<Response>}
       */
    const http = (config) =>  {
        return new Promise((resolve, reject) => {
          instance.request(config).then((response) => {
            if (response.data.code !== 200) {
             // 处理非code相关
            }
            resolve(response.data)
          }).catch((error) => {
            // 请求失败的处理
            reject(error)
          })
        })
    }
    export default http
    `
}

export const requestJsTemplate = () => {
  return `
    import http from "./axios"
    /**
     *  @type {Function}
     *  @param {url} string
     *  @param {params} any
     *  @return {Promise<Response>}
     */
     const get = (url, params) => http({
      method: 'get',
      url: url,
      params: params
     })
     
     /**
      *  @type {Function}
      *  @param {url} string
      *  @param {params} any
      *  @return {Promise<Response>}
      */
    const post = (url, params) => http({
      method: 'post',
      url: url,
      data: params
    })
    const request = {
      get,
      post,
    }

export default request
    
    `
}
